﻿using cio.trpl.wcf.protobuf.service;
using cio.trpl.wcf.protobuf.service.common;
using cio.trpl.wcf.service.protobuf.pocos;
using ProtoBuf.ServiceModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace cio.trpl.wcf.service.protobuf.client
{
	public class TestClient
	{
		static void Main(string[] args)
		{
			//ServiceReference.TrplServiceClient client = new ServiceReference.TrplServiceClient();

			//Stopwatch sw = new Stopwatch();
			
			//sw.Reset();
			//sw.Start();
			//TRPLRiskBucket[] res = client.GetTrplBucketedRiskPositions(new DateTime(2015, 2, 3));
			//sw.Stop();
			//Console.WriteLine("Elapsed: " + sw.ElapsedMilliseconds/1000 + " seconds");


			NetTcpBinding binding = new NetTcpBinding() { MaxReceivedMessageSize = 2000000000, MaxBufferSize = 2000000000 , MaxBufferPoolSize = 2000000000};
			binding.ReaderQuotas.MaxDepth = 32; 			
			EndpointAddress endPoint = new EndpointAddress("net.tcp://WR8WD31Y:9898/TrplService");
			ChannelFactory<ITrplService> channelFactory = new ChannelFactory<ITrplService>(binding, endPoint);
			channelFactory.Endpoint.Behaviors.Add(new ProtoEndpointBehavior());


			ITrplService _client = null;

			try
			{
				_client = channelFactory.CreateChannel();

				Stopwatch sw = new Stopwatch();
				sw.Reset();
				sw.Start();
				TRPLRiskBucket[] results = _client.GetTrplBucketedRiskPositions(new DateTime(2015, 2, 3));
				sw.Stop();
				Console.WriteLine("Elapsed: " + sw.ElapsedMilliseconds/1000 + " seconds");

				((ICommunicationObject)_client).Close();
			}
			catch
			{
				if (_client != null)
				{
					((ICommunicationObject)_client).Abort();
				}
			}

		}
	}
}
